package testadvance;

import java.util.*;

/**
 * @author oldliu
 * @since 1.0
 */
public class MapTest {
    public static void main(String[] args) {
        //二维的结构
        //key不允许重复，value可以，无序
        Map<String,String> m=new HashMap<>();
        m.put("狗","dog");
        m.put("猫","cat");
        m.put( "蛇","snake");
        m.put( "蛇","she");//覆盖
        m.put("大象","elephant");
        System.out.println(m.size());
        System.out.println(m);
        String s = m.get("大象");
        System.out.println(s);
        m.remove("蛇");
        System.out.println(m);
        System.out.println(">>>>>>>>>>>>>>>>>");
        //m.values获得值集合
        //m.keySet()key集合
        Iterator<String> ir = m.keySet().iterator();//获得所有的key
        while(ir.hasNext()){
            String key = ir.next();
            String value=m.get(key);
            System.out.println(key+"="+value);
        }
        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>");
        Set<Map.Entry<String, String>> entries = m.entrySet();
        Iterator<Map.Entry<String, String>> ir2 = entries.iterator();
        while(ir2.hasNext()){
            Map.Entry<String, String> n = ir2.next();
            System.out.println(n.getKey()+","+n.getValue());
        }
        //Cat key,
    }
}
